home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / games / mdlv13.zip / MDLSRC.ZIP / BG_MOUSE.CC < prev    next >
C/C++ Source or Header  |  1996-07-10  |  8KB  |  394 lines

  1. //
  2. // this file by brian martin 1996
  3. // brian@phyast.pitt.edu
  4. //
  5. // this is part of the source for the MedDLe quake model viewer/editor
  6. //
  7. //// mouse
  8. #include<go32.h>
  9. #include<dpmi.h>
  10. #include<stdlib.h>
  11. #include<stdio.h>
  12. #include"bg_mouse.h"
  13. #include"bg_grx.h"
  14.  
  15. #ifndef USEGRX
  16. #include <grx20.h>
  17. GrContext *MouseContext;
  18. GrContext *CrossHairCur;
  19. GrContext *PointingCur;
  20. GrContext *BackgroundContext;
  21. GrContext *TempContext;
  22. #endif
  23.  
  24. int bg_x,bg_y;
  25. #define MOUSE 0x33
  26.  
  27. __dpmi_regs r;
  28.  
  29. int BG_MouseLeft,
  30.     BG_MouseRight,
  31.     BG_MouseMiddle;
  32. int BG_MouseX,
  33.     BG_MouseY;
  34.  
  35. int HotX, HotY;
  36. int Speed;
  37.  
  38. void BG_InitMouse()
  39. {
  40.     // init mouse
  41.     r.x.ax = 0;
  42.     __dpmi_int(MOUSE,&r);
  43.     // hide
  44.     r.x.ax = 2;
  45.     __dpmi_int(MOUSE, &r);
  46.     BG_MouseRange(0,0,BG_ScreenWidth-1,BG_ScreenHeight-1);
  47.     // speed
  48.     BG_MouseSpeed(4);
  49.     BG_MouseToXY(BG_ScreenWidth>>1,BG_ScreenHeight>>1);
  50.     BG_MouseStatus();
  51.  
  52. #ifndef USEGRX
  53.  
  54.     MouseContext = GrCreateContext(16,16,NULL,NULL);
  55.     BackgroundContext = GrCreateContext(16,16,NULL,NULL);
  56.  
  57.  
  58.     CrossHairCur= GrCreateContext(16,16,NULL,NULL);
  59.     GrSetContext(CrossHairCur);
  60.     GrFilledBox(0,0,15,15,0);
  61.     GrBox(4,4,10,10,15);
  62.     GrFilledBox(4,6,10,8,0);
  63.     GrFilledBox(6,4,8,10,0);
  64.  
  65.     PointingCur=GrCreateContext(16,16,NULL,NULL);
  66.     GrSetContext(PointingCur);
  67.     GrFilledBox(0,0,15,15,0);
  68.     GrLine(0,0,10,10,15);
  69.     GrLine(0,0,0,14,15);
  70.     GrLine(0,14,4,10,15);
  71.     GrLine(4,10,10,10,15);
  72. //  GrLine(4,10,6,14,15);
  73.  
  74.    //   BG_MousePointing();
  75.     BG_MouseCrossHairs();
  76.     GrSetContext(NULL);
  77.     GrImageModeColor(0);
  78.     bg_x=BG_MouseX;
  79.     bg_y=BG_MouseY;
  80.  
  81. #endif
  82.  
  83. }
  84.  
  85. void BG_MousePointing(void)
  86. {
  87.     HotX=0;  HotY=0;
  88.  
  89.     GrBitBlt(MouseContext,
  90.             0,0,
  91.             PointingCur,
  92.             0,
  93.             0,
  94.             16,
  95.             16,
  96.             GrWRITE
  97.             );
  98.  
  99. }
  100. void BG_MouseCrossHairs(void)
  101. {
  102.     HotX=7;HotY=7;
  103.  
  104.     GrBitBlt(MouseContext,
  105.             0,0,
  106.             CrossHairCur,
  107.             0,
  108.             0,
  109.             16,
  110.             16,
  111.             GrWRITE
  112.             );
  113.  
  114. }
  115.  
  116. void BG_MouseStatus()
  117. {
  118.     r.x.ax = 3;
  119.     __dpmi_int(MOUSE,&r);
  120.     BG_MouseX = (r.x.cx>>3);
  121.     BG_MouseY = r.x.dx>>3;
  122.     BG_MouseLeft = ((r.x.bx & 0x01) != 0);
  123.     BG_MouseRight = ((r.x.bx & 0x02) != 0);
  124.     BG_MouseMiddle =   ((r.x.bx & 0x04) != 0);
  125. }
  126. void BG_MouseSpeed(int s)
  127. {
  128.     // speed
  129.     r.x.ax = 0x0f;
  130.     r.x.cx = s;
  131.     r.x.dx = s;
  132.     __dpmi_int(MOUSE, &r);
  133.  
  134. }
  135. void BG_MouseRange(int x1, int y1, int x2, int y2)
  136. {
  137.     r.x.ax = 7;
  138.     r.x.cx = (x1<<3);
  139.     r.x.dx = (x2<<3);
  140.     __dpmi_int(MOUSE,&r);
  141.     r.x.ax = 8;
  142.     r.x.cx = (y1<<3);
  143.     r.x.dx = (y2<<3);
  144.     __dpmi_int(MOUSE,&r);
  145. }
  146. void BG_MouseToXY(int xpos, int ypos)
  147. {
  148.    r.x.ax = 4;
  149.    r.x.cx = 8*(BG_MouseX = xpos);
  150.    r.x.dx = 8*(BG_MouseY = ypos);
  151.    __dpmi_int(MOUSE,&r);
  152. }
  153.  
  154. void BG_MouseShow(void)
  155. {
  156. #ifndef USEGRX
  157.  
  158. //  TempContext=GrCurrentContext();
  159.  
  160. //  GrSetContext(MouseContext);
  161.     GrBitBlt(BackgroundContext,
  162.             0,0,
  163.             NULL,
  164.             BG_MouseX-HotX,
  165.             BG_MouseY-HotY,
  166.             BG_MouseX+16-HotX,
  167.             BG_MouseY+16-HotY,
  168.             GrWRITE
  169.             );
  170.     bg_x=BG_MouseX;
  171.     bg_y=BG_MouseY;
  172.  
  173.     GrBitBlt(NULL,
  174.             BG_MouseX-HotX,BG_MouseY-HotY,
  175.             MouseContext,
  176.             0,
  177.             0,
  178.             16,
  179.             16,
  180.             GrIMAGE
  181.             );
  182. //  BG_PutPixel(BG_MouseX,BG_MouseY,15);
  183. //  GrSetContext(TempContext);
  184.  
  185. #endif
  186.  
  187.  
  188. }
  189.  
  190. void BG_MouseHide(void)
  191. {
  192. #ifndef USEGRX
  193.  
  194. //  TempContext=GrCurrentContext();
  195.  
  196. //  GrSetContext(MouseContext);
  197.     GrBitBlt(NULL,
  198.             bg_x-HotX,bg_y-HotY,
  199.             BackgroundContext,
  200.             0,
  201.             0,
  202.             16,
  203.             16,
  204.             GrWRITE
  205.             );
  206. /*
  207.     GrBitBlt(NULL,
  208.             BG_MouseX,BG_MouseY,
  209.             MouseContext,
  210.             0,
  211.             0,
  212.             16,
  213.             16,
  214.             GrIMAGE
  215.             );
  216. //  BG_PutPixel(BG_MouseX,BG_MouseY,15);
  217.     GrSetContext(TempContext);
  218.  */
  219. #endif
  220.  
  221.  
  222. }
  223.  
  224. /*
  225. #define INVSCRNMASK 0xFFFF
  226. #define INVCURSMASK 0x7700
  227. #define MOUSE 51
  228. #define ESC 0x1b            /* Define the escape key    */
  229. // mouse vars
  230. //union              REGS regs;
  231. //struct SREGS           sregs;
  232. /*
  233. int                              MouseOK = 0;
  234. int                              NoButtons = 2;
  235. int                              MidPressed,RightPressed,LeftPressed;
  236. MouseDef                         Mymouse;
  237. int                              MouseX = 0, MouseY = 0;
  238.  
  239. // bg mouse cur
  240. static BYTE * pMouseCursor;
  241. /* default 12x16 cursor (planar format) */
  242. /*static BYTE default_mouse_cursor[] = { 3, 0, 16, 0,
  243.      15,  0,  0, 15,  0,  0, 15,  0,  0, 15,  0,  0,
  244.      15, 15,  0, 15, 15,  0, 15, 15,  0, 15,  0,  0,
  245.      15,  0,  0,  0, 15,  0,  0, 15,  0,  0,  0,  0,
  246.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  247.       0,  0,  0, 15,  0,  0, 15,  0,  0, 15,  0,  0,
  248.      15,  0,  0, 15, 15,  0, 15, 15,  0, 15,  0,  0,
  249.       0,  0,  0,  0, 15,  0,  0, 15,  0,  0,  0,  0,
  250.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  251.       0,  0,  0,  0,  0,  0, 15,  0,  0, 15,  0,  0,
  252.      15,  0,  0, 15,  0,  0, 15, 15,  0, 15,  0,  0,
  253.      15,  0,  0, 15,  0,  0,  0,  0,  0,  0,  0,  0,
  254.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  255.       0,  0,  0,  0,  0,  0,  0,  0,  0, 15,  0,  0,
  256.      15,  0,  0, 15,  0,  0, 15,  0,  0, 15,  0,  0,
  257.      15,  0,  0, 15,  0,  0, 15,  0,  0,  0,  0,  0,
  258.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
  259. };
  260.  
  261.  
  262.  
  263. void InitMouse()
  264. {
  265.    regs.x.ax = 0;
  266.    int86(MOUSE,®s,®s);
  267.    MouseOK = regs.x.ax;
  268.    NoButtons = regs.x.bx;
  269. }
  270.  
  271. void ShowMouse()
  272. {
  273.    regs.x.ax = 1;
  274.    int86(MOUSE,®s,®s);
  275. }
  276.  
  277. void HideMouse()
  278. {
  279.    regs.x.ax = 2;
  280.    int86(MOUSE,®s,®s);
  281. }
  282.  
  283. void MouseXY()
  284. {
  285.    regs.x.ax = 3;
  286.    int86(MOUSE,®s,®s);
  287.    MouseX = regs.x.cx/2;
  288.    MouseY = regs.x.dx;
  289.    LeftPressed =  ((regs.x.bx & 0x01) != 0);
  290.    RightPressed = ((regs.x.bx & 0x02) != 0);
  291.    MidPressed =   ((regs.x.bx & 0x04) != 0);
  292. }
  293.  
  294. void MouseToXY(int xpos, int ypos)
  295. {
  296.    regs.x.ax = 4;
  297.    regs.x.cx = 2*(MouseX = xpos);
  298.    regs.x.dx = (MouseY = ypos);
  299.    int86(MOUSE,®s,®s);
  300. }
  301.  
  302. int MousePressCount(ButtonType button, int *status)
  303. {
  304.    regs.x.ax = 5;
  305.    regs.x.bx = button;
  306.    int86(MOUSE,®s,®s);
  307.    MouseX = regs.x.cx/2;
  308.    MouseY = regs.x.dx;
  309.    *status = regs.x.ax;
  310.    return regs.x.bx;
  311. }
  312.  
  313. int MouseReleaseCount(ButtonType button, int *status)
  314. {
  315.    regs.x.ax = 6;
  316.    regs.x.bx = button;
  317.    int86(MOUSE,®s,®s);
  318.    MouseX = regs.x.cx/2;
  319.    MouseY = regs.x.dx;
  320.    *status = regs.x.ax;
  321.    return regs.x.bx;
  322. }
  323.  
  324. void MouseXRange(int x1, int x2)
  325. {
  326.    regs.x.ax = 7;
  327.    regs.x.cx = x1*2;
  328.    regs.x.dx = x2*2;
  329.    int86(MOUSE,®s,®s);
  330. }
  331.  
  332. void MouseYRange(int y1, int y2)
  333. {
  334.    regs.x.ax = 8;
  335.    regs.x.cx = y1;
  336.    regs.x.dx = y2;
  337.    int86(MOUSE,®s,®s);
  338. }
  339. /*
  340. void DefineGraphMouse(MouseDef mouse, int xhot, int yhot)
  341. {
  342.    regs.x.ax = 9;
  343.    regs.x.bx = xhot;
  344.    regs.x.cx = yhot;
  345.    regs.x.dx = FP_OFF(&mouse);
  346.    sregs.es = FP_SEG(&mouse);
  347.    int86x(MOUSE,®s,®s,&sregs);
  348. }
  349. */
  350. /*
  351. void DefineTextMouse(MouseMode mode, int scrnmask, int cursormask)
  352. {
  353.    regs.x.ax = 10;
  354.    regs.x.bx = mode;
  355.    regs.x.cx = scrnmask;
  356.    regs.x.cx = cursormask;
  357.    int86(MOUSE,®s,®s);
  358. }
  359.  
  360. void ReadMouseMickey(int *Xspeed, int *Yspeed)
  361. {
  362.    regs.x.ax = 11;
  363.    int86(MOUSE,®s,®s);
  364.    *Xspeed = regs.x.cx;
  365.    *Yspeed = regs.x.dx;
  366. /*
  367.    if Xspeed > 0 then moving in positive x direction
  368.    if Yspeed > 0 then moving in positive y direction
  369. *//*
  370. }
  371.  
  372. void SetMouseMickey(int Xspeed, int Yspeed)
  373. {
  374.    regs.x.ax = 15;
  375.    regs.x.cx = (unsigned) Xspeed;
  376.    regs.x.dx = (unsigned) Yspeed;
  377.    int86(MOUSE,®s,®s);
  378. }
  379.  
  380. void TextCursorOff()
  381. {
  382.    regs.x.cx = 0x2000;
  383.    regs.x.ax = 0x0100;
  384.    int86(0x10,®s,®s);
  385. }
  386.  
  387.